<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
%>
<head>
    <script src="../assets/js/echarts.min.js"></script>
    <script src="../assets/js/jquery.min.js"></script>
    <script src="../assets/js/theme.js"></script>
    <script src="../assets/js/amazeui.min.js"></script>
    <script src="../assets/js/amazeui.datatables.min.js"></script>
    <script src="../assets/js/dataTables.responsive.min.js"></script>
    <%--    <script src="../assets/js/app.js"></script>--%>
</head>
<div class="container-fluid am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-9">
            <div class="page-header-heading"><span class="am-icon-home page-header-heading-icon"></span> 修改密码
                <small>个人管理</small></div>
            <p class="page-header-description"></p>
        </div>
    </div>
</div>

<div class="row-content am-cf">

    <div class="row">

        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-fl" id="change_pwd">修改密码</div>
                </div>
                <div class="widget-body am-fr">

                    <form class="am-form tpl-form-border-form" id="fm_updPwd">

                        <div class="am-form-group">
                            <label for="opwd" class="am-u-sm-12 am-form-label am-text-left">原密码 <span
                                    class="tpl-form-line-small-title">oid-password</span></label>
                            <div class="am-u-sm-12">
                                <input type="text" class="tpl-form-input am-margin-top-xs" id="opwd" name="opwd"
                                       placeholder="请输入原密码">
                            </div>
                            <div id="accountCheck"></div>
                        </div>

                        <div class="am-form-group">
                            <label for="npwd" class="am-u-sm-12 am-form-label am-text-left">新密码 <span
                                    class="tpl-form-line-small-title">new-password</span></label>
                            <div class="am-u-sm-12">
                                <input type="text" class="tpl-form-input am-margin-top-xs" id="npwd" name="npwd"
                                       placeholder="请输入新密码">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label for="rpwd" class="am-u-sm-12 am-form-label am-text-left">确认密码 <span
                                    class="tpl-form-line-small-title">retake-password</span></label>
                            <div class="am-u-sm-12">
                                <input type="text" class="tpl-form-input am-margin-top-xs" id="rpwd" name="rpwd"
                                       placeholder="请再次输入密码">
                            </div>
                            <div id="pwdValidate"></div>
                        </div>

                        <div class="am-form-group">
                            <div class="am-u-sm-12 am-u-sm-push-12">
                                <button type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success "
                                        id="bt_updPwd">提交
                                </button>
                            </div>
                            <div id="changeFail"></div>
                        </div>

                    </form>

                </div>
            </div>
        </div>
    </div>

</div>
<script src="../assets/js/jquery-3.3.1.min.js"></script>
<script>

    // 验证用户名密码
    $('#opwd').blur(function () {
        var opwd = $("#opwd").val();
        if (opwd == null || opwd == "") {
            $("#accountCheck").text("原密码不能为空！");
            $("#accountCheck").css("color", "red");
            return false;
        }
        $.ajax({
            type: "POST",
            url: "<%=path%>/admin/IsOldPwdServlet.do",
            data: {opwd: opwd},
            success: function (result) {
                var jsonResult = $.parseJSON(result);
                //alert(jsonResult.state);
                if (jsonResult.state == 1000) {
                    $("#accountCheck").text("")
                } else {
                    $("#accountCheck").text(jsonResult.msg);
                    $("#accountCheck").css("color", "red");
                }
            }
        });
    });
    //验证新密码和确认密码是否一致
    $("#cpwd").blur(function () {
        var npwd = $("#npwd").val();
        var cpwd = $("#cpwd").val();
        if (npwd == cpwd) {
            $("#pwdValidate").text("");
        } else {
            $("#pwdValidate").text("新密码不一致");
            $("#pwdValidate").css("color", "red");
            return false;
        }
    });

    $("#bt_updPwd").click(function () {
        var inputData = $("#fm_updPwd").serialize();
        alert(inputData);
        $.ajax({
            async: true,
            type: 'POST',
            url: '<%=path%>/admin/ChangePwdServlet.do',
            data: inputData,
            success: function (result) {
                var jsonResult = $.parseJSON(result)
                alert(jsonResult.state)
                if (jsonResult.state == 1000) {
                    alert("修改成功");
                    $("#changeFail").html("");
                } else {
                    $("#changeFail").html(jsonResult.msg);
                    $("#changeFail").css("color", "red");
                }
            }
        });
    });
</script>

